package com.ssy.lingxi.order.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.order.model.constant.DeliveryHistoryTypeEnum;
import com.ssy.lingxi.order.model.constant.DeliveryOrderTypeStatusEnum;
import com.ssy.lingxi.order.model.vo.basic.request.*;
import com.ssy.lingxi.order.model.vo.basic.response.*;
import com.ssy.lingxi.order.service.web.IDeliveryOrderService;
import com.ssy.lingxi.order.service.web.IDeliveryPlanService;
import com.ssy.lingxi.order.service.web.IReceiveOrderService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 订单能力 - 送货计划
 * @author czh
 * @version 2.0.0
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/order/deliveryPlan")
public class DeliveryPlanController {

    @Resource
    private IDeliveryPlanService planService;

    /**
     * “送货计划” - 送货计划协同 - 分页查询
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/vendor/page", method = RequestMethod.GET)
    public Wrapper<PageData<DeliveryPlanQueryVO>> pageByVendorPlan(@RequestHeader HttpHeaders headers, @Valid DeliveryPlanPageVO request) {
        return planService.pageVendorDeliveryPlan(headers, request);
    }

    /**
     * “送货计划” - 送货计划 - 分页查询
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/buyer/page", method = RequestMethod.GET)
    public Wrapper<PageData<DeliveryPlanQueryVO>> pageByBuyer(@RequestHeader HttpHeaders headers, @Valid DeliveryPlanPageVO request) {
        return planService.pageBuyerDeliveryPlan(headers, request,request.getOrderType());
    }

    /**
     * “送货计划” - 查询计划周期内的计划送货物料
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/order/product/page", method = RequestMethod.GET)
    public Wrapper<PageData<DeliveryPlanProductQueryVO>> pageByOrderProductSRM(@RequestHeader HttpHeaders headers, @Valid DeliveryPlanProductPageVO request) {
        return planService.pagePlanProducts(headers, request);
    }

    /**
     * “送货计划” - 新增送货计划（SRM）
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/srm/create", method = RequestMethod.POST)
    public Wrapper<Void> createBySRM(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryPlanCreateVO request) {
        return planService.createDeliveryPlan(headers, request, DeliveryOrderTypeStatusEnum.SRM.getCode());
    }


    /**
     * “送货计划” - 新增送货计划（B2B）
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 新增结果
     */
    @RequestMapping(value = "/b2b/create", method = RequestMethod.POST)
    public Wrapper<Void> createByB2B(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryPlanCreateVO request) {
        return planService.createDeliveryPlan(headers, request, DeliveryOrderTypeStatusEnum.B2B.getCode());
    }

    /**
     * “送货计划” - 详情
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Wrapper<DeliveryPlanDetailVO> detail(@RequestHeader HttpHeaders headers, @Valid IdVO request) {
        return planService.getDeliveryPlanDetail(headers, request);
    }

    /**
     * “送货计划” - 详情 - 流转记录
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/deliveryHistory", method = RequestMethod.GET)
    public Wrapper<List<DeliveryOuterHistoryVO>> deliveryHistory(@RequestHeader HttpHeaders headers, @Valid IdVO request) {
        return planService.deliveryHistory(headers, request, DeliveryHistoryTypeEnum.DELIVERY_PLAN.getCode());
    }

    /**
     * “送货计划” - 详情 - 物料分页列表
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail/product/page", method = RequestMethod.GET)
    public Wrapper<PageData<DeliveryPlanProductQueryVO>> pageProducts(@RequestHeader HttpHeaders headers, @Valid IdPageVO request) {
        return planService.getDeliveryPlanProductDetail(headers, request);
    }

    /**
     * “送货计划” - 修改送货计划
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 返回结果
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<Void> update(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryPlanUpdateVO request) {
        return planService.updateDeliveryPlan(headers, request);
    }

    /**
     * “送货计划” - 删除送货计划
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 返回结果
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Wrapper<Void> delete(@RequestHeader HttpHeaders headers, @RequestBody @Valid IdVO request) {
        return planService.deleteDeliveryPlan(headers, request);
    }

    /**
     * “送货计划” - 确认送货计划
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 返回结果
     */
    @RequestMapping(value = "/confirm", method = RequestMethod.POST)
    public Wrapper<Void> confirm(@RequestHeader HttpHeaders headers, @RequestBody @Valid DeliveryVerifyVO request) {
        return planService.confirmDeliveryPlan(headers, request);
    }

    /**
     * “送货计划” - 提交送货计划
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 返回结果
     */
    @RequestMapping(value = "/submit", method = RequestMethod.POST)
    public Wrapper<Void> submit(@RequestHeader HttpHeaders headers, @RequestBody @Valid IdVO request) {
        return planService.submitDeliveryPlan(headers, request);
    }


    /**
     * 送货计划-生成送货通知单所需数据
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/noticeOrder", method = RequestMethod.GET)
    public Wrapper<NoticeOrderParamByPlanVO> NoticeOrderByPlanCreate(@RequestHeader HttpHeaders headers, @Valid NoticeOrderByPlanCreateVO request) {
        return planService.NoticeOrderByPlanCreate(headers, request);
    }

    /**
     * 送货计划-生成送货单所需数据
     * @param headers HttpHeaders信息
     * @param request 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/deliveryOrder", method = RequestMethod.GET)
    public Wrapper<DeliveryOrderCreateByPlanVO> DeliveryOrderByPlanCreate(@RequestHeader HttpHeaders headers, @Valid DeliveryOrderByPlanCreateVO request) {
        return planService.DeliveryOrderByPlanCreate(headers, request);
    }
}
